package com.test.langchain4j.controller;

import com.test.langchain4j.service.MySQLMcpService;
import com.test.langchain4j.service.OracleMcpService;
import com.test.langchain4j.service.RedisMcpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 2025/8/8 15:17
 * @modifiedBy:
 * @version: 1.0
 */
@Slf4j
@RestController
public class DbMcpCallServerController {
  @Autowired private OracleMcpService oracleMcpService;

  @Autowired private RedisMcpService redisMcpService;

  @Autowired private MySQLMcpService mySQLMcpService;

  @GetMapping("/mcp/oracle/chat")
  public Flux<String> chatOracle(@RequestParam("question") String question) {
    log.info("Received question for Oracle MCP: {}", question);
    return oracleMcpService.chat(question);
  }

  @GetMapping("/mcp/redis/chat")
  public Flux<String> chatRedis(@RequestParam("question") String question) {
    return redisMcpService.chat(question);
  }

  /**
   * Chat mysql flux.
   * http://localhost:9014/mcp/mysql/chat?question=请查询mysql数据库testdb中是否有一张名为dm_user的表，如果没有，请在testdb中创建这张表，包括id
   * ，用户名，密码，创建时间等字段，并插入10条测试数据
   *
   * @param question the question
   * @return the flux
   */
  @GetMapping("/mcp/mysql/chat")
  public Flux<String> chatMysql(@RequestParam("question") String question) {
    return mySQLMcpService.chat(question);
  }
}
